﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;
using Microsoft.AspNet.SignalR;
using OASystem.BLL.IService;
using OASystem.BLL.Service;
using OASystem.Common;

using OASystem.Model;
using OASystem.Models;
using OASystem.ViewModel;

namespace OASystem.Controllers
{
    public class MesageController : Controller
    {
        private IMesageService _mesageService;
        private IMesage_tailService _tailService;
        private ILoginService _loginService;
        public MesageController(IMesageService mesageService, IMesage_tailService tailService, ILoginService loginService)
        {
            _mesageService = mesageService;
            _tailService = tailService;
            _loginService = loginService;
        }

        // GET: Mesage
        public ActionResult Index()
        {
            return View();
        }

        //获取所有的消息
        public JsonResult GetMesageList(int page, int limit)
        {
            Expression<Func<Messagepush, bool>> lambdaExpression = a => true;

            PageListResult<Messagepush> pageList = new PageListResult<Messagepush>();
            pageList.data = _mesageService.QueryList(lambdaExpression).Skip((page - 1) * limit).Take(limit).ToList(); ;
            pageList.count = _mesageService.QueryList(lambdaExpression).Count;
            return Json(pageList, JsonRequestBehavior.AllowGet);
        }


        /// <summary>
        /// 获取所有部门信息
        /// </summary>
        /// <returns></returns>
        public JsonResult Getdepartment()
        {
            Expression<Func<Departinfo, bool>> lambdaExpression = a => true;
            PageListResult<Departinfo> pageList = new PageListResult<Departinfo>();
            pageList.data= _tailService.QueryList(lambdaExpression);
            return Json(pageList);
        }


        /// <summary>
        /// 根据部门Id查询用户
        /// </summary>
        /// <returns></returns>
        public JsonResult GetUserbydepartId(int departId)
        {
            Expression<Func<Userinfo, bool>> lambdaExpression = a => a.DepartId==departId;
            PageListResult<Userinfo> pageList = new PageListResult<Userinfo>();
            pageList.data = _loginService.QueryList(lambdaExpression);
            return Json(pageList);
        }


        public JsonResult AddMesage(Messagepush messagepush, int departId)
        {
            
            Operate op = new Operate();
            Expression<Func<Userinfo, bool>> lambdaExpression = a => a.DepartId == departId;
            List<Userinfo> userinfos = _loginService.QueryList(lambdaExpression);
        
         

            
          
            return Json(op);
        }

       






    }
}